<script language="javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js "></script>
<script language="javascript" src="http://api.weixinzjit.com/api/www/js/wx_jsapi_v_1.0.js"></script>
<script language="JavaScript">

var ShareTitle = '快来倾听我为你定制的祝福树';
var ShareDesc = "浓情岁末，定制语音祝福树传递感谢与思念，立邦与你一起刷又一年。";
var ShareUrl = 'http://api.weixinzjit.com/lb/index.php';
var ShareImg = 'http://api.weixinzjit.com/lb/img/share_ico.jpg';


var isPlay = false;
var CT = 1;

var ApiList = [
	//与分享有关的接口
	'onMenuShareTimeline',
	'onMenuShareAppMessage',
	//与声音有关的接口
	'translateVoice', 'playVoice', 'pauseVoice',
	'stopVoice', 'onVoicePlayEnd', 'downloadVoice'
];

function resetShare() {
	wx.onMenuShareAppMessage({
		title: ShareTitle,
		desc: ShareDesc,
		link: ShareUrl,
		imgUrl: ShareImg,
		trigger: function(res) { /* alert('用户点击发送给朋友'); */ },
		success: function(res) { /* alert('已分享'); */ },
		cancel: function(res) { /* alert('已取消'); */ },
		fail: function(res) { /* alert(JSON.stringify(res)); */ }
	});
	wx.onMenuShareTimeline({ // 2.2 监听"分享到朋友圈"按钮点击、自定义分享内容及分享结果接口
		title: ShareDesc,
		link: ShareUrl,
		imgUrl: ShareImg,
		trigger: function(res) { /* alert('用户点击分享到朋友圈'); */ },
		success: function(res) { /* alert('已分享'); */ },
		cancel: function(res) { /* alert('已取消'); */ },
		fail: function(res) { /* alert(JSON.stringify(res)); */ }
	});
}
var CallbackList = function() {
	//页面载入完成后 下载语音 
	wx.downloadVoice({
		serverId: voice.serverId,
			//语音下载完成
			success: function(res) {
				voice.localId = res.localId.toString(); 
				$('.play_btn').fadeIn();
			},
			//语音已过期
			fail: function(res) {
				alert('语音已过期！');
			}
		}); 
	resetShare(); 
	initBo();
	$('.play_btn').bind('touchstart', function(ev) {
		ev.preventDefault();
		if(isPlay) return false;
		if(voice.localId.length<1){
			alert('load vioce error'); return false;
		}
		isPlay = true; 
		wx.playVoice({
			localId: voice.localId
		}); 
		playbo();
	});
	wx.onVoicePlayEnd({
		complete: function(res) {
			isPlay = false;
		}
	});
	
	
	$('.music').bind('touchstart',function(ev){
		ev.preventDefault();
		var music = document.getElementById('music');
		if($(this).hasClass('music_play')){
			$(this).removeClass('music_play').addClass('music_stop');
			music.pause();
		}else{
			$(this).removeClass('music_stop').addClass('music_play');
			music.play();
		}
	});
};

function initBo(){
	var tp = $('body').attr('d_type');
	$('.p5_tree').empty();
	for(i=1;i<4;i++){
		$('.p5_tree').append('<img src="img/p5_tree_'+tp+'_'+i+'.png" class="tr_'+i+'" />');	
	}
	$('.p5_tree img').bind('touchstart',function(ev){ ev.preventDefault(); });
}

function playbo(){
	if(isPlay){
		setTimeout(function(){
			$('.p5_tree img').hide();
			CT = (CT++)%3+1;
			$('.p5_tree .tr_'+CT).show();
			playbo();
		},300);
	}
}

$(function(){
	ZJWX(ApiList,CallbackList,false);
});
</script>